package dev.werillib.android

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment

/**
 * create by weril 2018/11/26
 */

fun Activity.skip(toActivity: Activity, bundle: Bundle? = null) {
    val intent: Intent = Intent().setClass(this, toActivity::class.java)
    bundle?.let {
        intent.putExtras(bundle)
    }
    startActivity(intent)
}

fun Fragment.skip(toActivity: Activity, bundle: Bundle? = null) {
    context?.let {
        val intent: Intent = Intent().setClass(it, toActivity::class.java)
        bundle?.let {
            intent.putExtras(bundle)
        }
        startActivity(intent)
    }
}

fun Activity.skipForResult(
    toActivity: Activity,
    requestCode: Int,
    bundle: Bundle? = null
) {
    val intent = Intent()
    intent.setClass(this, toActivity::class.java)
    bundle?.let {
        intent.putExtras(bundle)
    }
    startActivityForResult(intent, requestCode)
}

fun Fragment.skipForResult(
    toActivity: Activity,
    requestCode: Int,
    bundle: Bundle? = null
) {
    context?.let {
        val intent = Intent()
        if (bundle != null) {
            intent.putExtras(bundle)
        }
        intent.setClass(it, toActivity::class.java)
        startActivityForResult(intent, requestCode)
    }
}

